package bishijie.spider;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.alibaba.fastjson.JSONObject;

import bishijie.entity.Bishijie;
import bishijie.entity.TheDate;
import jodd.datetime.JDateTime;
import jodd.http.HttpRequest;

public class SpiderBishijie {
	private static final String url = "http://www.bishijie.com/api/news/?size=50&timestamp=1519263018";
	
	
	public static void main(String[] args) {
//		Bishijie spider = new SpiderBishijie().spider();
//		System.out.println(spider);
		
		System.out.println(new JDateTime(1519337461000l));
		System.out.println(new JDateTime(1519287823000l));
		
		
		
	}
	
	public Bishijie spider(){
		String json = HttpRequest.get(url).send().bodyText();
		JSONObject JsonObj = JSONObject.parseObject(json);
		JSONObject jsonObject = JsonObj.getJSONObject("data");
		Set<String> keySet = jsonObject.keySet();
		List<TheDate> dateObjs = new ArrayList<TheDate>();
		for (String theDate : keySet) {
			TheDate dateObj = JSONObject.parseObject(jsonObject.getString(theDate), TheDate.class);
			dateObjs.add(dateObj);
		}
		return new Bishijie(JsonObj.getIntValue("error"),JsonObj.getString("message"),dateObjs);
	}
}
